home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / acceschk.rxx < prev    next >
Text File  |  1996-11-05  |  6KB  |  244 lines

  1. /* Check acesss privs module for SRE-FILTER. Uses contents of accessfile 
  2. Standard arguments on initialization: access_file, queue, semaphore
  3. Caller places on queue: newq,newsem,AURL
  4. This put on newq: amatch,privs,options,realm
  5.   amatch= entry number of match (0 if NOt match)
  6.   privs = entry privileges
  7.   options = CACHE NOSSI NOSSP
  8.   realm = realm to use for "ask client for id stuff"
  9. Options and realm are often not available.
  10. */
  11.  
  12. parse upper arg accessfile,  usequeue , USESEM, max_semwait
  13. call pmprintf(' SRE-FILTER Access Thread: accessfile='||accessfile)
  14. call pmprintf(' SRE-FILTER Access Thread: queue='||usequeue)
  15. call pmprintf(' SRE-FILTER Access Thread: semaphore='||usesem)
  16. mytid=dostid()
  17. call pmprintf(' SRE-FILTER Access Thread: thread id='||mytid)
  18.  
  19.  
  20. resetit:
  21. if usequeue="" | USESEM="" then do
  22.    call pmprintf('SRE-FILTER Access thread: initialization ERROR: '||usequeue)
  23.    exit
  24. end
  25.  
  26. call set_access(accessfile)
  27. if naccess=0 then do
  28.    call pmprintf(' SRE-FILTER access thread: Warning: No valid entries in access file:'||accessfile)
  29. end
  30. else do
  31.    call pmprintf(' SRE-FILTER access thread:  #acesss entries='||naccess)
  32. end
  33.  
  34. /* Initialization now done == start waiting for requests for access info */
  35. signal on error name iserror
  36. signal on syntax name iserror
  37. bakme:
  38.  a=rxqueue('s',usequeue)
  39.  aq=queued()
  40.  if aq=0 then do
  41.     WOW=EVENTSEM_WAIT(USESEM,max_semwait)
  42.     aq=-1
  43.     if wow=640 then do
  44.      signal bakme
  45.     end
  46.     IF WOW<>0 THEN do         /* FATAL ERROR */
  47.         call pmprintf(' Fatal error in access thread 'wow)
  48.         EXIT
  49.     end
  50.  end
  51.  
  52.  wow=EVENTSEM_RESET(usesem)
  53.  if aq=-1 then
  54.      if queued()=0 then signal bakme
  55.  
  56.  pull isit0
  57.  
  58.  isit0=upper(translate(isit0,' ','000d0a09'x))
  59.  if isit0=" " then signal bakme
  60.  
  61.      parse var isit0  idnum ','  newq ',' newsem ',' ISIT
  62.      parse var idnum idnum host_nickname 
  63.  
  64.      if newq="" | newsem="" then do
  65.         call pmprintf(' SRE-FILTER access Thread: missing queue or semaphore ')
  66.         signal bakme
  67.      end
  68.      newq=strip(newq); newsem=strip(newsem) ; ISIT=STRIP(ISIT)
  69.  
  70.     if abbrev(strip(translate(isit)),'*DIE*') then 
  71.          exit
  72.  
  73.  
  74.     if abbrev(strip(translate(isit)),'*RESET*') then do
  75.        parse var isit foo newfile .
  76.        if newfile<>' ' then accessfile=newfile
  77.        call set_access(accessfile)
  78.        call pmprintf(' SRE-Filter access: Reread access file:'accessfile)
  79.    end
  80.    else do
  81.       if naccess=0 then
  82.         dog1=' 0 '
  83.       else do
  84.         dog1=fig_access(isit,host_nickname)
  85.       end
  86.       a=rxqueue('s',newq)
  87.       push idnum ',' dog1
  88.       wow=eventsem_post(newsem)
  89.    end
  90.  
  91.  
  92. signal bakme
  93.  
  94. iserror:
  95. signal off error ; signal off syntax
  96. call pmprintf(' error in access : resetting ')
  97. a=rxqueue('d',usequeue)
  98. a=rxqueue('c',usequeue)
  99. a=eventsem_close(usesem)
  100. a=eventsem_create(usesem)
  101. a=rxqueue('s',newq)
  102. push idnum  ', 0 '
  103. wow=eventsem_post(newsem)
  104. call pmprintf(' done resetting access ')
  105. signal on error name iserror
  106. signal on syntax name iserror
  107. signal bakme
  108.  
  109.  
  110. exit
  111.  
  112.  
  113. /* ---------- */
  114. fig_access:procedure expose urls. privs. opts. realms. nrealms realm_names. realm_privs. hosturls.
  115.   parse arg inline,host_nickname
  116.   inline=strip(translate(inline,' ','000d0a09'x))
  117.   inline=translate(inline,'/','\')
  118.   inline=strip(inline,'l','/')
  119.   host_nickname=strip(upper(host_nickname))
  120.  
  121. /* got a request -- look for a match */
  122. doexact=0
  123.  gotit=0
  124.  starat=0 ;  afterstar=0
  125.  do mm=1 to urls.0
  126.     if hosturls.mm<>host_nickname & hosturls.mm<>' ' then iterate
  127.  
  128.     ma1=urls.mm
  129.     ares=sref_wildcard(inline,ma1,doexact)
  130.     parse var ares astat "," aurl ;  astat=strip(astat)
  131.     if astat=0 then iterate   /* no match */
  132.     if astat=1 then do
  133.         gotit=mm
  134.         leave           /*first exact match rules */
  135.     end
  136.     else  do
  137.        parse var ma1 ma1a ma1b
  138.        t1=pos('*',ma1a)
  139.        t33=length(ma1a)-t1
  140.        if t1 >= starat  then do
  141.           if t1 > starat | t33>afterstar then do
  142.  
  143.              starat=t1 ; afterstar=t33
  144.              gotit=mm
  145.           end
  146.        end
  147.  
  148.     end
  149.  end
  150.  
  151. if gotit=0 then
  152.    return gotit
  153.  
  154.  
  155. pgot=privs.gotit
  156. if realms.gotit<>"" then do     /* find realm privs? */
  157.     do nn1=1 to nrealms
  158.         if realms.gotit=realm_names.nn1 then do
  159.                pgot=pgot||' '||realm_privs.nn1
  160.                leave
  161.         end
  162.     end
  163. end
  164. return gotit ' , ' pgot ',' opts.gotit ', ' realms.gotit
  165.  
  166.  
  167.  
  168.  
  169. /* ---------------- */
  170. /* read and set up access privs */
  171. set_access:
  172. parse arg afile
  173.  
  174. naccess=0 
  175. nrealms=0
  176. urls.0=0
  177. a=fileread(afile,'ulist',,'E')   /* read it to a stem variable */
  178. foo=do_extends(0)
  179. if a=0 then do
  180.       call pmprintf(' SRE-FILTER access thread: ERROR reading access-file: '||afile)
  181.       return 0
  182. end
  183.  
  184. do mm=1 to ulist.0
  185.      t1=translate(strip(ulist.mm))
  186.      if abbrev(t1,';')=1 | t1=' 'then
  187.            iterate
  188.  
  189.      ahost=' '
  190.      t1w=strip(upper(word(t1,1)))
  191.      if right(t1w,2)='//' then do
  192.          ahost=left(t1w,length(t1w)-2)
  193.          t1=strip(delword(t1,1,1))
  194.      end
  195.  
  196.      if upper(word(t1,1))='!REALM' then do
  197.          nrealms=nrealms+1
  198.          parse upper var t1 foo1 realm_names.nrealms  realm_privs.nrealms
  199.          iterate
  200.      end
  201.  
  202.      parse upper var t1 aurl  privs ',' options ',' realm
  203.      naccess=naccess+1
  204.      aurl=strip(aurl) 
  205.      aurl=translate(aurl,'/','\')
  206.      aurl=strip(aurl,'l','/')
  207.      urls.naccess=aurl
  208.      privs.naccess=strip(privs)
  209.      opts.naccess=strip(options)
  210.      realms.naccess=strip(realm)
  211.      hosturls.naccess=ahost
  212. end
  213. urls.0=naccess
  214.  
  215.  
  216. return 0
  217.  
  218.  
  219.  
  220.  
  221. /************/
  222. /* Redo ulist, by treating lines starting with , as continuation lines */
  223. do_extends:procedure expose ulist.
  224. if ulist.0=0 then return 0
  225. isnew=1
  226. tmps.1=ulist.1
  227. do mm=2 to ulist.0
  228.    ali=strip(ulist.mm)
  229.    if abbrev(ali,',')=0 then do
  230.         isnew=isnew+1
  231.         tmps.isnew=ulist.mm
  232.     end
  233.     else do
  234.         tmps.isnew=tmps.isnew||substr(ali,2)
  235.     end
  236. end
  237. do mm=1 to isnew
  238.     ulist.mm=tmps.mm
  239. end
  240. ulist.0=isnew
  241. return 0
  242.  
  243.  
  244.